#ifndef ShellBase_h
#define ShellBase_h

#include <QObject>
#include <QVariant>


class ShellBase : public QObject
{
	Q_OBJECT
public:
    typedef QMap<QString,QObject*> TargetMap;

    ShellBase(QObject *parent = nullptr);
    virtual ~ShellBase();

    Q_SIGNAL void sigEvent(QString event, QVariant info);

protected:
    void shell(QObject *target);
    void shell(const TargetMap &target);
    virtual void config(const QVariant &param) {Q_UNUSED(param)}
    virtual QVariant action(const QString &action, const QVariant &param=QVariant()){Q_UNUSED(action);Q_UNUSED(param);return QVariant();}

protected:
    /**
     * @brief resetTarget 派生类不要再使用此函数进行target的初始化，改为使用installTarget
     * @param name
     * @param target
     */
    virtual void resetTarget(const QString &name, QObject *target);
    virtual void installTarget(const QString &name, QObject *target){}
    virtual void uninstallTarget(const QString &name, QObject *target){}
    QObject* target(const QString &name="");
    template<class T>
    T* ttarget(const QString &name="");

    Q_SLOT virtual void onTargetDeleted(QObject *object);

private:
    QMap<QString,QObject*> _target;
};

#endif
